package utils;

import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.Display;

public class ViewUtils {
	
	public static int screenWidth;
	
	public static int screenHeight;
	
	public static int displayDensity;
	
	public static void intitialize(Activity a){
		Display display = a.getWindowManager().getDefaultDisplay();
		DisplayMetrics metrics = new DisplayMetrics();
		display.getMetrics(metrics);
		screenWidth = display.getWidth();
		screenHeight = display.getHeight();
		displayDensity = Math.round(metrics.density);	
	}
	
	public static int getPixelsFromMillimetres(int mm){
		// The gesture threshold expressed in dp

		// Get the screen's density scale
		float scale = displayDensity;
		// Convert the dps to pixels, based on density scale
		int pixels = (mm * displayDensity/254);
		
		return pixels;
		// Use mGestureThreshold as a distance in pixels...
	}
	
	public static int getPixelsFromInches(float inch){

		// The gesture threshold expressed in dp

		// Get the screen's density scale
		float scale = displayDensity;
		// Convert the dps to pixels, based on density scale
		int pixels = (int) (inch * displayDensity);
		
		return pixels;
		// Use mGestureThreshold as a distance in pixels..
	}

	public static int percentWidthToPixels(int percentWidth) {
		int pixels = Math.round(percentWidth*screenWidth/100);
		return pixels;
	}
	public static int percentHeightToPixels(int percentHeight){
		int pixels = Math.round(percentHeight*screenHeight/100);
		return pixels;
		
	}
	

	

}
